﻿using System;

namespace JanusLibAing.Conditions
{
    /// <summary>
    /// state machine exit condition
    /// it is possible 9 different exit conditions.
    /// </summary>
    public class DefaultExitCondition : Condition
    {
        //exit codes
        public enum EExitCode
        {
            EXIT_NOT_DEFINED = -3,
            EXIT_NOTHING_TODO = -2, // it is error state too, state maschine not finished correctly
            EXIT_ON_ERROR = -1,
            EXIT_OK = 0,
            EXIT_NOT_OK = 1,
            EXIT_USER1 = 2,
            EXIT_USER2 = 3,
            EXIT_USER3 = 4,
            EXIT_USER4 = 5,
            EXIT_USER5 = 6,
            EXIT_USER6 = 7,
            EXIT_USER7 = 8,
            //public const int EXIT_USER8 = 9;
            EXIT_ON_BREAK = 9,

            EXIT_ABORTED = EXIT_ON_BREAK, // create synonim
        }

        protected EExitCode exitId = 0;

        // constructor for cloning
        protected DefaultExitCondition()
        {
        }

        /// <summary>
        /// exit state
        /// </summary>
        /// <param name="exitId"></param>
        public DefaultExitCondition(EExitCode exitId)
            : base(EConditionType.EXIT_CONDITION_START + (int)exitId)
        {
            this.exitId = exitId;
            int ExitConditionMax = (EConditionType.EXIT_CONDITION_END - EConditionType.EXIT_CONDITION_START);
            if (exitId < 0 || (int)exitId > ExitConditionMax)
            {
                throw new ArgumentOutOfRangeException("exitId", string.Format("must be in range {0}..{1}", 0, ExitConditionMax)); //MLHIDE
            }
        }

        public EExitCode ExitId
        {
            get { return exitId; }
        }

        public override string ToString()
        {
            return "Exit " + base.ToString();                                  //MLHIDE
        }
    }
}